package com.jltx.xq.videoeditorlearnpro;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import butterknife.ButterKnife;

/**
 * @author jltxseo
 *         Created by junlintianxia on 2018/03/02.
 * @version V1.0
 * @Description
 */

public abstract class BaseFragment extends Fragment{
    private View rootView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        if(rootView == null){
            int contentViewId = provideContentViewId();
            rootView = inflater.inflate(contentViewId,container,false);
            ButterKnife.bind(this, rootView);
            initView(rootView,savedInstanceState);
        }else {
            ViewGroup parent = (ViewGroup) rootView.getParent();
            if (parent != null) {
                parent.removeView(rootView);
            }
        }
        return rootView;
    }


    /**
     * 得到当前界面的布局文件id(由子类实现)
     * @return
     */
    protected abstract int provideContentViewId();

    /**
     * 初始化一下View
     * @param rootView
     * @param savedInstanceState
     */
    public void initView(View rootView, Bundle savedInstanceState) {
    }


}
